﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.Forms.Local
{
    public class Relation
    {
        public Relation(DataGrid Table)
        {
            this.m_Table = Table;
        }

        public DataGrid ChildTable
        {
            get
            {
                return this.m_Table;
            }
        }
        private DataGrid m_Table;



        [DefaultValue(null)]
        public DataGrid Table
        {
            get
            {
                return this.m_ParentTable;
            }
            set
            {
                if (this.m_ParentTable != value)
                {
                    if (this.m_ParentTable != null && this.m_ParentTable.ChildRelation.Contains(this))
                        this.m_ParentTable.ChildRelation.Remove(this);

                    this.m_ParentTable = value;

                    if (this.m_ParentTable != null && this.m_ParentTable.ChildRelation.Contains(this) == false)
                        this.m_ParentTable.ChildRelation.Add(this);
                }
            }
        }
        private DataGrid m_ParentTable;


        [DefaultValue(typeof(SyncLoadModeEnum), "None")]
        public SyncLoadModeEnum SyncLoadMode { get; set; } = SyncLoadModeEnum.None;


        [EditorBrowsable(EditorBrowsableState.Always)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<RelationColumn> Items
        {
            get
            {
                if (m_Items == null)
                    m_Items = new List<RelationColumn>();
                return m_Items;
            }
        }
        private List<RelationColumn> m_Items;
    }
}
